package com.seed.service;

import com.seed.entity.User;
import com.seed.qo.UserQo;
import com.seed.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ThreadLocalRandom;

@RestController
public class UserServiceImpl implements UserService {

    private Log log = LogFactory.getLog(getClass());

    @Override
    public Result<User> get(Integer id) {
        try {
            Thread.sleep(5000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("id=" + id);
        User user = new User();
        user.setId(id);
        user.setName("name" + id);
        return Result.success(user);
    }

    @Override
    public Result<Integer> save(User user) {
        System.out.println("name|" + user.getName());
        return Result.success(ThreadLocalRandom.current().nextInt(1000));
    }

    @Override
    public Result<User> query(UserQo userQo) {
        System.out.println("name|" + userQo.getName());
        User user = new User();
        user.setId(ThreadLocalRandom.current().nextInt(1000));
        user.setName(userQo.getName());
        return Result.success(user);
    }
}
